package com.lancoo.znbkxx.teacher.ui.fragment

import android.content.Intent
import androidx.recyclerview.widget.LinearLayoutManager
import com.lancoo.znbkxx.teacher.R
import com.lancoo.znbkxx.teacher.adapter.ExampleWrongQuesAdapter
import com.lancoo.znbkxx.teacher.adapter.SpacesItemDecoration
import com.lancoo.znbkxx.teacher.base.BaseVMFragment
import com.lancoo.znbkxx.teacher.databinding.FmtExampleWrongQuesBinding
import com.lancoo.znbkxx.teacher.ui.activity.AddWrongQuesActivity
import com.lancoo.znbkxx.teacher.utils.DensityUtils
import com.lancoo.znbkxx.teacher.viewmodel.HardSolutionViewModel
import kotlinx.android.synthetic.main.fmt_example_wrong_ques.*


/**
 * @author : Admin
 * @date   : 2020/10/28
 * @desc   :
 */
class ExampleWrongQuesFragment :
        BaseVMFragment<HardSolutionViewModel, FmtExampleWrongQuesBinding>() {
    private val typeName by lazy { arguments?.getString("typeName") }
    lateinit var adapter: ExampleWrongQuesAdapter
    override fun setLayoutID(): Int {
        return R.layout.fmt_example_wrong_ques
    }

    override fun providerContext(): Any? {
        return activity
    }

    override fun providerVMClass(): Class<HardSolutionViewModel>? {
        return HardSolutionViewModel::class.java
    }

    override fun initView() {
        val manager = LinearLayoutManager(requireContext())
        rv.layoutManager = manager
        adapter = ExampleWrongQuesAdapter(typeName!!,
                viewModel.answerSkillComment.value!!.ClassicWrongQues)
        val emptyView = layoutInflater.inflate(R.layout.view_empty, null)
        adapter.emptyView = emptyView
        val hashMap = hashMapOf<String, Int>()
        hashMap[SpacesItemDecoration.TOP_SPACE] = DensityUtils.dp2px(context, 5f)
        rv.addItemDecoration(SpacesItemDecoration(hashMap))
        rv.adapter = adapter
        tv_change.setOnClickListener {
            activity?.startActivityForResult(
                    Intent(requireContext(), AddWrongQuesActivity::class.java).apply {
                        putExtra("typeNo", viewModel.answerSkillComment.value!!.TypeNo)
                        putExtra("genreID", viewModel.answerSkillComment.value!!.GenreID)
                        putExtra("ids",viewModel.answerSkillComment.value!!.ClassicWrongQues)
                    }, 200)
        }
    }
}